#ifndef CRESOURCEMANAGER_H_
#define CRESOURCEMANAGER_H_

#include <QObject>
#include <QVector>
#include <QFile>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>

class CResDownloadObj : public QObject
{
	Q_OBJECT 

public:
	explicit CResDownloadObj(int id, const QString& url, const QString& filepath);
	~CResDownloadObj();

Q_SIGNALS:
	void downloadProgress(int id, qint64 cur, qint64 total);
	void downloadFinished(int id, bool flag, QString filepath);

protected Q_SLOTS:
	void event_net_error(QNetworkReply::NetworkError code);
	void event_net_finished();
	void event_net_ready_read();

private:
	QFile*		file_;
	QString		filepath_;
	QString		url_;
	int			id_;
};

class CResourceManager : public QObject
{
	Q_OBJECT
public:
	enum EResType {
		EResType_Installer		= 0,

		EResType_ADMain			= 1,
		EResType_ADTop			= 2,
		EResType_ADBottom		= 3,

		EResType_ADWait			= 4
	};

	CResourceManager() = default;
	~CResourceManager() = default;

	void Upgrade(QString filename);
	void LoadResource(int32_t type, QString url);
	QString GetUrlFilename(const QString& url);

protected:
	void download_resource(int type, const QString& url);
	QString get_url_file_name(const QString& url);
	bool check_local_cache_file(const QString& filename);

Q_SIGNALS:
	void resourceDownloadFinished(int type, bool flag, QString filepath);
	void resourceDownloadProgress(int type, qint64 cur, qint64 total);
	void installFinished();
};

#endif // CRESOURCEMANAGER_H_